package com.site.wisdom_construction.controller.personnelModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.personnelModule.EducationSecurityQuestionsRecordService;
import com.site.wisdom_construction.util.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/3/28
 * @Description
 */
@Api(tags = "入岗教育安全培训考试记录接口")
@RestController
@RequestMapping("EducationSecurityQuestionsRecord")
@CrossOrigin
public class EducationSecurityQuestionsRecordController {
    @Autowired
    private EducationSecurityQuestionsRecordService educationSecurityQuestionsRecordService;

    @ApiOperation(value = "增加入岗教育安全培训考试记录", notes = "测试数据:")
    @PostMapping("/insertEducationSecurityQuestionsRecord")
    public JsonResult insertEducationSecurityQuestionsRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationSecurityQuestionsRecordService.insertEducationSecurityQuestionsRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入入岗教育安全培训考试记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入入岗教育安全培训考试记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除入岗教育安全培训考试记录", notes = "测试数据:")
    @PostMapping("/deleteEducationSecurityQuestionsRecord")
    public JsonResult deleteEducationSecurityQuestionsRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = educationSecurityQuestionsRecordService.deleteEducationSecurityQuestionsRecord(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除入岗教育安全培训考试记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除入岗教育安全培训考试记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改入岗教育安全培训考试记录", notes = "测试数据:")
    @PostMapping("/updateEducationSecurityQuestionsRecord")
    public JsonResult updateEducationSecurityQuestionsRecord(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        map.put("updateDate", TimeUtils.getNowTime());
        int i = educationSecurityQuestionsRecordService.updateEducationSecurityQuestionsRecord(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改入岗教育安全培训考试记录!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改入岗教育安全培训考试记录失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询入岗教育安全培训考试记录", notes = "请求参数:pageNo,pageSize,projectId,模糊查询参数:workerName,workerCard,liabilityName")
    @PostMapping("/findEducationSecurityQuestionsRecordByPage")
    public Page findEducationSecurityQuestionsRecordByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(educationSecurityQuestionsRecordService.Total(map));
        page.setItems(educationSecurityQuestionsRecordService.findEducationSecurityQuestionsRecordByPage(map));
        return page;
    }

    @ApiOperation(value = "根据id查询入岗教育安全培训考试记录", notes = "请求参数:id")
    @PostMapping("/findEducationSecurityQuestionsRecordById")
    public OneDataResult findEducationSecurityQuestionsRecordById(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(educationSecurityQuestionsRecordService.findEducationSecurityQuestionsRecordById(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据工人身份证号查询对应入岗教育安全培训考试记录信息", notes = "请求参数:workerCard")
    @PostMapping("/findEducationSecurityQuestionsRecordByWorkerCard")
    public OneDataResult findEducationSecurityQuestionsRecordByWorkerCard(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(educationSecurityQuestionsRecordService.findEducationSecurityQuestionsRecordByWorkerCard(map));
        return oneDataResult;
    }

    @ApiOperation(value = "分页模糊查询教育负责人对应的入岗教育安全培训考试记录", notes = "请求参数:pageNo,pageSize,projectId,managerialId,模糊查询参数:workerName,workerCard,liabilityName")
    @PostMapping("/findEducationSecurityQuestionsRecordByManagerialId")
    public Page findEducationSecurityQuestionsRecordByManagerialId(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(educationSecurityQuestionsRecordService.TotalByManagerialId(map));
        page.setItems(educationSecurityQuestionsRecordService.findEducationSecurityQuestionsRecordByManagerialId(map));
        return page;
    }
}
